package collection;

import space.position.Point;

import java.util.Collection;
import java.util.Iterator;

/**
 * Iterator<E>接口
 * 迭代器
 *
 * 迭代器遍历过程中不能通过集合方法来增删元素，否则会报错异常
 * 需要用迭代器中的方法删除元素
 * iterator.remove()        删除next()方法获取得元素
 * */
public class IteratorDemo {
    public static void main(String[] args) {
        Point[] points = GetArray.randomPointArray(10, 20, 30, 0, 6);
        Collection<Point> pointCollection = Get.getArrayList(points);
        Iterator<Point> iterator = pointCollection.iterator();
        while (iterator.hasNext()) {
            Point point = iterator.next();
            if (point.getY() < 3)
                iterator.remove();
            System.out.println(point);
        }
        System.out.println(pointCollection);
    }
}
